package com.imti.mall.sale.controller;

import cn.hutool.json.JSONArray;
import com.imti.mall.common.Api.CommonPage;
import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.sms.from.SmsCouponProductRelationFrom;
import com.imti.mall.model.sms.pojo.SmsCouponProductRelation;
import com.imti.mall.model.sms.pojo.SmsFlashPromotionSession;
import com.imti.mall.sale.service.SmsFlashPromotionSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/sale")
@Api(tags = "限时购场次表")
public class SmsFlashPromotionSessionController {
    @Autowired
    SmsFlashPromotionSessionService smsFlashPromotionSessionService;
    @ApiOperation("查询限时购场次表")
    @PostMapping(value = "/findSmsFlashPromotionSession")
    public CommonResult findSmsFlashPromotionSession(){
        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.findSmsFlashPromotionSession();
        if(list.size()>0){
            return CommonResult.success(CommonPage.restPage(list));
        }else {
            return CommonResult.success("未查询到信息");
        }
    }

    @ApiOperation("根据id删除时购场次表")
    @PostMapping(value = "/delSmsFlashPromotionSession/{id}")
    public CommonResult delSmsFlashPromotionSession(@PathVariable("id") Integer id){
        Integer integer = smsFlashPromotionSessionService.delSmsFlashPromotionSession(id);
        if(integer>0){
            return CommonResult.success("删除成功");
        }
        return CommonResult.failed("删除失败");
    }

    @ApiOperation("根据id修改时购场次表")
    @PostMapping(value = "/updateSmsFlashPromotionSession/{id}")
    public CommonResult updateSmsFlashPromotionSession(@PathVariable("id") Long id,@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        Integer integer = smsFlashPromotionSessionService.updateSmsFlashPromotionSession(smsFlashPromotionSession);
        if(integer>0){
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }

    @ApiOperation("根据id修改时购场次表状态")
    @PostMapping(value = "/updateSmsFlashPromotionSessionByStatus/{id}")
    public CommonResult updateSmsFlashPromotionSessionByStatus(@PathVariable("id") Long id, SmsFlashPromotionSession smsFlashPromotionSession){
        smsFlashPromotionSession.setId(id);
        Integer integer = smsFlashPromotionSessionService.updateSmsFlashPromotionSession(smsFlashPromotionSession);
        if(integer>0){
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }

    @ApiOperation("添加时购场次表")
    @PostMapping(value = "/addSmsFlashPromotionSession")
    public CommonResult addSmsFlashPromotionSession( @RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        Integer integer = smsFlashPromotionSessionService.add(smsFlashPromotionSession);
        if(integer>0){
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }
}
